package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Student;
import com.example.demo.mapper.StudentMapper;
import com.example.demo.service.StudentService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public List<Student> queryStudentsByCondition(String name, Integer minAge, Integer maxAge, String gender) {
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(name)) {
            queryWrapper.like(Student::getName, name);
        }
        if (minAge != null) {
            queryWrapper.ge(Student::getAge, minAge);
        }
        if (maxAge != null) {
            queryWrapper.le(Student::getAge, maxAge);
        }
        if (StringUtils.hasText(gender)) {
            queryWrapper.eq(Student::getGender, gender);
        }
        return this.list(queryWrapper);
    }
}    